﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Models
{
    public class UserInfo
    {
        public virtual int Id { get; set; }
        /// <summary>
        /// Gets or sets the customer Guid
        /// </summary>
        public virtual Guid UserGuid { get; set; }

        public virtual string UserName { get; set; }
        public virtual string Email { get; set; }
        public virtual string Password { get; set; }
        public virtual string PasswordSalt { get; set; }
        public virtual string Intro{ get; set; }
        public virtual string UserLogo{ get; set; }


        /// <summary>
        /// Gets or sets a value indicating whether the customer is active
        /// </summary>
        public virtual bool Active { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether the customer has been deleted
        /// </summary>
        public virtual bool Deleted { get; set; }

        public virtual DateTime CreatedOn { get; set; }

        public virtual int PasswordFormatId { get; set; }
        public virtual PasswordFormat PasswordFormat
        {
            get { return (PasswordFormat)PasswordFormatId; }
            set { this.PasswordFormatId = (int)value; }
        }

        public UserType UserType { get; set; }

        private ICollection<RoleInfo> _roles;



        /// <summary>
        /// Gets or sets the customer roles
        /// </summary>
        public virtual ICollection<RoleInfo> Roles 
        {
            get { return _roles ?? (_roles = new List<RoleInfo>()); }
            protected set { _roles = value; }
        }


        public bool IsRegistered()
        {
            var result = Roles.Where(cr => cr.RoleName == SystemCustomerRoleNames.Registered)
               .FirstOrDefault() != null;
            return result;
        }
    }

    public enum PasswordFormat : int
    {
        Clear = 0,
        Hashed = 1,
        Encrypted = 2
    }
}